package star.插入排序;

import star.Utils;

/*
*
*
* */
public class InsertionSort {
    public static void main(String[] args) {
        int[] arr = {4,2,6,7,1,9,8,5,4};
        InsertionSort.insertionSort(arr);
        Utils.traversal(arr);
    }

    public static void insertionSort(int[] arr) {
        if (arr.length<2 || arr==null){
            return;
        }
        for (int i = 1; i < arr.length; i++) {
            for (int j = i-1; j >= 0;j--){
                if (arr[j] > arr[j+1]){
                    Utils.swap(arr,j,j+1);
                }
            }
        }
    }
}
